feat(functions): add low-level functions.fetch API#141
Conversation
Add a native fetch-based functions.fetch(path, init) method for streaming use cases where invoke() buffers responses. Include JSON data convenience, endpoint fallback compatibility, and unit tests for routing and auth headers. Made-with: Cursor
|
Claude finished @netanelgilad's task —— View job Code Review FeedbackReview Checklist
SummaryOverall, this is a well-implemented feature that adds streaming support to the Base44 SDK. The code follows good patterns and includes comprehensive test coverage. I've identified some areas for improvement below. Code Quality & Best Practices ✅Strengths:
Suggestions:
Potential Bugs 🐛
Performance Considerations 🚀Good:
Could improve:
Security Concerns 🔒Good practices:
Minor concern:
Test Coverage 📋Excellent coverage including:
Missing tests:
Additional Recommendations
VerdictThe implementation is solid and ready for use. The suggestions above are mostly for improving maintainability and edge case handling. Great work on adding this streaming capability! 🎉 |
🚀 Package Preview Available!Install this PR's preview build with npm: npm i @base44-preview/sdk@0.8.21-pr.141.dd114e6Prefer not to change any import paths? Install using npm alias so your code still imports npm i "@base44/sdk@npm:@base44-preview/sdk@0.8.21-pr.141.dd114e6"Or add it to your {
"dependencies": {
"@base44/sdk": "npm:@base44-preview/sdk@0.8.21-pr.141.dd114e6"
}
}
Preview published to npm registry — try new features instantly! |
netanelgilad
left a comment
There was a problem hiding this comment.
@claude address the comments
|
Claude finished @netanelgilad's task —— View job Completed Tasks
SummaryI've addressed all the review comments:
All tests are passing and the build is successful. The |
- Remove fallback path logic - only use /functions endpoint - Remove X-App-Id header - not needed - Remove automatic content-type handling - let fetch handle it natively - Update tests to reflect the simplified behavior Co-authored-by: Netanel Gilad <netanelgilad@users.noreply.github.com>
netanelgilad
left a comment
There was a problem hiding this comment.
@claude address the comments
|
Claude finished @netanelgilad's task —— View job Completed Tasks
SummaryI've successfully addressed both review comments:
Additional changes made:
All tests are passing and the build is successful. The |
- Remove body handling/transformation logic - fetch now acts as a pure wrapper - Only append common headers from axios defaults, not post-specific headers - Remove isBodyInit helper function as it's no longer needed - Update tests to use body instead of data property - Update type definitions to use RequestInit directly Co-authored-by: Netanel Gilad <netanelgilad@users.noreply.github.com>
- Add FunctionsModuleConfig interface with getAuthHeaders and baseURL options - Pass auth header getter function from client to functions module - Remove direct axios usage in fetch method for better separation of concerns - Maintain backward compatibility by making config optional Co-authored-by: Netanel Gilad <netanelgilad@users.noreply.github.com>
|
Claude finished @netanelgilad's task —— View job Code Review CompletedReview Checklist
SummaryThe PR successfully implements a streaming-friendly Code Quality & Best Practices
|
|
Claude finished @netanelgilad's task —— View job Code Review for feat(functions): add streaming-friendly functions.fetch APIReview Checklist
Overall AssessmentThe implementation of the streaming-friendly Code Quality & Best Practices ✅Strengths:
Minor Suggestions:
Architecture & Design 🏗️The refactoring to remove axios dependency is excellent:
Potential Bugs 🐛Critical Issue: Name shadowing at src/modules/functions.ts:103 const response = await fetch(
joinBaseUrl(config?.baseURL, primaryPath),
requestInit
);The local const response = await globalThis.fetch(
joinBaseUrl(config?.baseURL, primaryPath),
requestInit
);Performance Considerations 🚀Good:
Suggestions:
Security Review 🔒Excellent practices:
No security issues found. Test Coverage 📋Well tested:
Missing coverage:
SummaryThis PR successfully adds a clean, streaming-friendly fetch API to the SDK. The removal of axios dependency improves the architecture. The only critical issue is the Recommendation: Fix the fetch shadowing issue, then approve and merge. |
- Updated getAuthHeaders functions in client.ts to compute Authorization headers directly - User modules now use token from config or getAccessToken() utility - Service role modules use serviceToken directly - Fixed double '/api' prefix in functions.ts since baseURL already contains it This reduces dependency on axios internals in preparation for eventual axios removal. Co-authored-by: Netanel Gilad <netanelgilad@users.noreply.github.com>
|
Claude finished @netanelgilad's task —— View job Completed Tasks
SummaryI've successfully addressed your review comments:
All tests are passing (111 tests passed) and the build completed successfully. The changes have been committed and pushed to the branch. |
- Remove test for 404 fallback behavior (no longer relevant) - Simplify streaming test to just test basic fetch functionality Co-authored-by: Netanel Gilad <netanelgilad@users.noreply.github.com>
Updated the JSDoc comment to describe all use cases for the fetch method, not just streaming. Now mentions custom HTTP methods, headers, raw response access, and direct body control as additional reasons to use fetch over invoke. Co-authored-by: Netanel Gilad <netanelgilad@users.noreply.github.com>
|
move and address:
|
|
Claude finished @netanelgilad's task —— View job Completed Tasks
SummarySuccessfully completed all requested changes:
All 113 tests are passing and the build completed successfully. The changes have been committed and pushed to the branch. |
- Moved FunctionsModuleConfig interface from functions.ts to functions.types.ts - Added test for path normalization (with/without leading slash) - Added test for service role auth using asServiceRole.functions.fetch Co-authored-by: Netanel Gilad <netanelgilad@users.noreply.github.com>
Summary
base44.functions.fetch(path, init)for low-level HTTP requests to backend functions with native fetch interfaceKey Features
This PR adds a new
functions.fetchmethod that complements the existing high-levelinvokemethod:Use Cases
Implementation Details
/api/functions/<path>Test Plan
npm run test:unit -- tests/unit/functions.test.tsnpm run buildMade with Cursor